package com.choosefine.it.manager.controller;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.team.model.vo.PersonInfoDetailVO;
import com.choosefine.it.team.service.TeamHomePageService;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 潘钱钦 上午10:20:25
 * 
 */
@RestController
@RequestMapping("/managerHomePage")
@Api(value = "项目经理个人主页", description = "毛俊")
public class ManagerHomePageController extends BaseController {

	@Autowired
	private TeamHomePageService teamHomePageService;

	@ApiOperation(value = "根据用户的usercode获取用户的主页详情", notes = "", response = PersonInfoDetailVO.class)
	@ApiImplicitParam(name = "userCode", value = "用户的usercode", required = true, dataType = "String", paramType = "path")
	@RequestMapping(value = "/getManagerHomePageDetail/{userCode}", method = RequestMethod.GET)
	public String getManagerHomePageByUserCode(@PathVariable String userCode)
			throws JsonProcessingException {
		String result = null;
		PersonInfoDetailVO p = teamHomePageService.getPersonDetailInfoByUserCode(userCode);
		if (p != null) {
			result = responseSuccess(p, ResultCode.SUCCESS, ResultCode.MSG_QUERY_SUCCESS);
		} else {
			result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
		}
		return result;
	}
}
    /*@ApiIgnore
	@ApiOperation(value = "根据用的usercode获取用户的主页", notes = "",response=ManagerPersonalCenter.class)
	@ApiImplicitParam(name = "userCode", value = "用户的usercode", required = true, dataType = "String", paramType = "path")
	@RequestMapping(value = "/getManagerHomePage/{userCode}", method = RequestMethod.GET)
	public String getManagerHomePage(@PathVariable String userCode)
			throws JsonProcessingException {
		String result = null;
		if (userCode != null && !"".equals(userCode)) {
			String url = URLHandlerUtils.getUrlBuffer(shixiaobaoURL,  userinfoURL).append(userCode).toString();
			Map userInfoResultMap = restTemplate.getForObject(url, Map.class,new HashMap<>());
			Map userInfo = (Map) userInfoResultMap.get("data");
			logger.info("序列化结果 :\n"
					+ jsonObjectMapper.writeValueAsString(userInfo));
			if (userInfo.isEmpty()) {
				result = responseFail(ResultCode.SERVERERROR_INTERNAL,
						ResultCode.MSG_USERNOTEXIT);
			} else {
				String realName = (String) userInfo.get("realName");
				String nativePlace = (String) userInfo.get("nativePlace");
				Integer userAge = (Integer) userInfo.get("userAge");
				String headIconUrl = (String) userInfo.get("headIconUrl");
				Integer sex = (Integer) userInfo.get("sex");
				ManagerPersonalCenter managerPersonalCenter = new ManagerPersonalCenter();
				managerPersonalCenter.setRealName(realName);
				managerPersonalCenter.setNativePlace(nativePlace);
				managerPersonalCenter.setHeadIconUrl(headIconUrl);
				managerPersonalCenter.setSex(sex);
				managerPersonalCenter.setUserAge(userAge);
				result = responseSuccess(managerPersonalCenter,
						ResultCode.SUCCESS, ResultCode.MSG_SUCCESS);

		}
		}else{
			result = responseFail(ResultCode.SERVERERROR_INTERNAL,
					ResultCode.MSG_PARAMS_NULL);
		}
		return result;
	}
}
*/